<template>
	<view class="login-wrapper" :style="colorStyle">
		<view class="login-top"></view>
		<view class="shading">
			<image :src="logoUrl" v-if="logoUrl" />
			<image :src="`${imgHost}logo-login.png`" v-else />
		</view>
		<view class="whiteBg" v-if="formItem === 1">

			<view class="tips">
				<view class="tips-btn" :class="current == 0 ? 'on' : ''" @click="current = 0">
					<view>账号登录</view>
					<view :class="current == 0 ? 'line' : 'none'"></view>
				</view>
				<view class="tips-btn" :class="current == 1 ? 'on' : ''" @click="current = 1">
					<view>快速登录</view>
					<view :class="current == 1 ? 'line' : 'none'"></view>
				</view>
			</view>
			
			<!-- 账号登录 -->
			<view class="list" v-if="current == 0 || appLoginStatus || appleLoginStatus">
				<form @submit.prevent="submit">
					<view class="item">
						<view class="acea-row row-middle">
							<image class="itemImg-add" :src="`${imgHost}phone_1.png`"></image>
							<input type="text" placeholder="输入手机号码" v-model="account" maxlength="11" required />
						</view>
					</view>
					<view class="item">
						<view class="acea-row row-middle">
							<image class="item-img" :src="`${imgHost}code_1.png`"></image>
							<input type="password" placeholder="填写登录密码" v-model="password" required />
						</view>
					</view>
				</form>
				<navigator class="forgetPwd" hover-class="none" url="/pages/users/retrievePassword/index">
					忘记密码?
				</navigator>
			</view>
			
			<!-- 快速登录 -->
			<view class="list" v-if="current == 1">
				<view class="item">
					<view class="acea-row row-middle">
						<image class="itemImg-add" :src="`${imgHost}phone_1.png`"></image>
						<input type="text" placeholder="注册手机号码" v-model="account" maxlength="11" />
					</view>
				</view>
				<view class="item">
					<view class="acea-row row-middle">
						<image class="item-img" :src="`${imgHost}code_2.png`"></image>
						<input type="text" placeholder="手机验证码" maxlength="6" class="codeIput" v-model="captcha" />
						<button class="code" :disabled="disabled" :class="disabled === true ? 'on' : ''" @click="code">
							{{ text }}
						</button>
					</view>
				</view>
			</view>
			
			<!-- 登录按钮 -->
			<view class="logon" @click="submit()" v-if="current === 0">登录</view>
			<view class="logon" @click="loginMobile()" v-if="current == 1">登录</view>
			<view class="register" @click="formItemTab(2)">注册</view>
			
			<!-- #ifdef APP-PLUS -->
			<view class="appLogin" v-if="!appLoginStatus && !appleLoginStatus">
				<view class="hds">
					<span class="line"></span>
					<p>其他方式登录</p>
					<span class="line"></span>
				</view>
				<view class="btn-wrapper">
					<view class="btn wx" @click="wxLogin">
						<span class="iconfont icon-s-weixindenglu1"></span>
					</view>
					<view class="btn pingguo" @click="appleLogin" v-if="appleShow">
						<view class="iconfont icon-s-pingguo"></view>
					</view>
				</view>
			</view>
			<!-- #endif -->
			
			<view class="protocol">
				<checkbox-group @change='ChangeIsDefault'>
					<checkbox :class="inAnimation?'trembling':''" @animationend='inAnimation=false' :checked="protocol ? true : false" />
					已阅读并同意<text class="main-color" @click="privacy('user')">《用户协议》</text>
					与<text class="main-color" @click="privacy('privacy')">《隐私协议》</text>
				</checkbox-group>
			</view>
		</view>
		
		<view class="whiteBg" v-if="formItem === 2">
			<!-- 快速注册 -->
			<view class="list">
				<view class="item">
					<view class="acea-row row-middle">
						<image class="InvitationCode address" :src="`${imgHost}role.png`"></image>
						<view class="uni-list-cell-left">
							当前身份<text class="iconfont icon-xiangyou"></text>
						</view>
						<view class="uni-list-cell-db">
							<picker @change="bindPickerChange" :value="role" :range="array">
								<view class="uni-input">{{array[role]}}</view>
							</picker>
						</view>
					</view>
				</view>
				<view class="item on" v-if="isHouseType">
					<view class="acea-row row-middle">
						<image class="InvitationCode address" :src="`${imgHost}role.png`"></image>
						<view class="uni-list-cell-left">
							选择类别<text class="iconfont icon-xiangyou"></text>
						</view>
						<view class="uni-list-cell-db">
							<picker @change="houseTypeChange" :value="houseTypeIndex" :range="houseType">
								<view class="uni-input">{{houseType[houseTypeIndex]}}</view>
							</picker>
						</view>
					</view>
				</view>
				
				<view class="item on" v-if="isArea">
					<view class="acea-row acea-row row-middle">
						<view style="width: 200rpx; padding: 0;" class="acea-row row-middle">
							<image class="InvitationCode address" :src="`${imgHost}role.png`"></image>
							<view class="uni-list-cell-left">
								选择项目<text class="iconfont icon-xiangyou"></text>
							</view>
						</view>
						<view style="width: 270rpx; padding: 0;" class="acea-row row-between-wrapper">
							<view class="uni-list-cell-db">
								<picker @change="projectChange" :value="projectIndex" :range="projectList">
									<view class="uni-input">{{projectList[projectIndex]}}</view>
								</picker>
							</view>
							<view class="uni-list-cell-left on" @click="addApply()">
								<text class="iconfont icon-jia"></text>
							</view>
						</view>
					</view>
				</view>
				
				<view class="item" v-if="isArea">
					<view class="acea-row row-middle">
						<image class="InvitationCode" :src="`${imgHost}area.png`"></image>
						<input type="text" placeholder="请输入房号" v-model="room" />
					</view>
				</view>
				
				<view class="item" v-if="isArea">
					<view class="acea-row row-middle">
						<image class="InvitationCode" :src="`${imgHost}area.png`"></image>
						<input type="text" placeholder="请输入总面积/m²" v-model="acreage" />
					</view>
				</view>
				
				<view class="item on" v-if="isIdeal">
					<view class="acea-row row-middle">
						<image class="InvitationCode address" :src="`${imgHost}role.png`"></image>
						<view class="uni-list-cell-left">
							选择想要<text class="iconfont icon-xiangyou"></text>
						</view>
						<view class="uni-list-cell-db">
							<picker @change="wantToChange" :value="wantToIndex" :range="wantTo">
								<view class="uni-input">{{wantTo[wantToIndex]}}</view>
							</picker>
						</view>
					</view>
				</view>
				<view class="item" v-for="(item, index) of addressList" :key="index" v-if="isIdeal">
					<view class="acea-row row-center-wrapper">
						<image class="InvitationCode address" :src="`${imgHost}city.png`"></image>
						<input type="text" placeholder="自定义区域" v-model="item.name" @input="setValue" @tap="inputConfirm(item)" />
						<view class="seting acea-row row-center-wrapper" style="padding: 0;">
							<view class="iconfont icon-jiahao" style="margin-right: 20rpx;" @click="add(index)"></view>
							<view class="iconfont icon-jianhao" @click="del(index)"></view>
						</view>
					</view>
				</view>
				
				<view class="item">
					<view class="acea-row row-middle">
						<image class="InvitationCode" :src="`${imgHost}contact.png`"></image>
						<input type="text" placeholder="请输入联系人" v-model="real_name" maxlength="11" />
					</view>
				</view>
				<view class='item'>
					<view class="acea-row row-middle">
						<image class="InvitationCode" :src="`${imgHost}city.png`"></image>
						<view class="addressCon acea-row" @click="changeRegion">
							<text class="picker color-add" v-if="!cityInfo.length">请选择地址</text>
							<view v-else>
								<text class="picker">{{addressText}}</text>
							</view>
						</view>
					</view>
				</view>
				<view class='item'>
					<view class="acea-row row-middle">
						<image class="InvitationCode" :src="`${imgHost}address-book.png`"></image>
						<input type='text' placeholder='请填写具体地址' v-model='addres'></input>
					</view>
				</view>
				<view class="item">
					<view class="acea-row row-middle">
						<image class="itemImg-add" :src="`${imgHost}phone_1.png`"></image>
						<input type="text" placeholder="注册手机号码" v-model="account" maxlength="11" />
					</view>
				</view>
				<view class="item">
					<view class="acea-row row-middle">
						<image class="item-img" :src="`${imgHost}code_1.png`"></image>
						<input type="password" placeholder="设置登录密码" v-model="password" required />
					</view>
				</view>
				<view class="item">
					<view class="acea-row row-middle">
						<image class="item-img" :src="`${imgHost}code_2.png`"></image>
						<input type="text" placeholder="手机验证码" maxlength="6" class="codeIput" v-model="captcha" />
						<button class="code" :disabled="disabled" :class="disabled === true ? 'on' : ''" @click="code">
							{{ text }}
						</button>
					</view>
				</view>
				<view class="item">
					<view class="acea-row row-middle">
						<image class="InvitationCode" :src="`${imgHost}InvitationCode.png`"></image>
						<view class="input-box">
							<input type="text" placeholder="推荐邀请码" v-model="invitationCode" confirm-type="send" @confirm="sendText" />
							<text class="iconfont icon-yanzhengma" @click="sendText" :class="{ isSend: isSend }">验证推荐人</text>
						</view>
					</view>
				</view>
				
				<view class="user-info" v-if="isVerify">
					<view class="user-info-top acea-row row-center-wrapper">
						<view class="top-image">
							<image class="InvitationCode" :src="recommended.avatar"></image>
						</view>
						<view class="top-nickname">
							{{nameShow(recommended.nickname)}}<text>{{phoneNumShow(recommended.phone)}}</text>
						</view>
					</view>
					<view class="user-info-down">
						邀请您加入{{site_name}}
					</view>
				</view>
			</view>
			<!-- 注册按钮 -->
			<view class="logon" @click="register()">注册</view>
			<view class="register" @click="formItemTab(1)">登录</view>
			<view class="protocol">
				<checkbox-group @change='ChangeIsDefault'>
					<checkbox :class="inAnimation?'trembling':''" @animationend='inAnimation=false' :checked="protocol ? true : false" />
					已阅读并同意<text class="main-color" @click="privacy('user')">《用户协议》</text>
					与<text class="main-color" @click="privacy('privacy')">《隐私协议》</text>
				</checkbox-group>
			</view>
		</view>
		<vcode :show="isShow" @success="onSuccess()" @close="onClose()" successText="行为验证通过" />
		<areaWindow ref="areaWindow" :display="display" :address="cityInfo" @submit="OnChangeAddress" @changeClose="changeClose"></areaWindow>
		<applyWindow :change="change" :dataer="h5Data" v-on:closeChange="closeChange($event)" v-on:saveApply="saveApply"></applyWindow>
	</view>
</template>

<script>
	const app = getApp();
	import {
		loginH5,
		loginMobile,
		registerVerify,
		register,
		getCodeApi,
		getUserInfo,
		appleLogin,
		recommendedByApi,
		applySaveApi
	} from "@/api/user";
	import attrs, {
		required,
		alpha_num,
		chs_phone
	} from "@/utils/validate";
	import {
		validatorDefaultCatch
	} from "@/utils/dialog";
	import {
		getLogo
	} from "@/api/public";
	import {
		getIndexData,
		wechatAppAuth
	} from "@/api/api";
	import {
		VUE_APP_API_URL
	} from "@/utils";
	import {
	  HTTP_REQUEST_URL
	} from '@/config/app';

	const BACK_URL = "login_back_url";
	import areaWindow from '@/components/areaWindow';
	import dayjs from "@/plugin/dayjs/dayjs.min.js";
	import sendVerifyCode from "@/mixins/SendVerifyCode";
	import applyWindow from '@/components/applyWindow';
	import Vcode from "vue-puzzle-vcode";
	import colors from '@/mixins/color.js';
	import { config } from "process";
	export default {
		name: "Login",
		components: {
		    Vcode,
			areaWindow,
			applyWindow
		},
		mixins: [sendVerifyCode, colors],
		data: function() {
			return {
				inAnimation: false,
				protocol: false,
				navList: ["账号登录", "快速登录"],
				current: 0,
				account: "",
				password: "",
				captcha: "",
				formItem: 1,
				type: "login",
				logoUrl: "",
				keyCode: "",
				codeUrl: "",
				codeVal: "",
				appLoginStatus: false, // 微信登录强制绑定手机号码状态
				appUserInfo: null, // 微信登录保存的用户信息
				appleLoginStatus: false, // 苹果登录强制绑定手机号码状态
				appleUserInfo: null,
				appleShow: false, // 苹果登录版本必须要求ios13以上的
				keyLock: true,
				isShow: false,
				imgHost: `${HTTP_REQUEST_URL}/statics/images/`,
				invitationCode: '',
				isVerify: false,
				site_name: '',
				recommended: {},
				array: ['租房', '房东', '专职经纪人','兼职经纪人'],
				
				isHouseType: false,
				houseType: ['商办','厂房','住宅'],
				houseTypeIndex: 0,
				
				
				role: 0,
				display: false,
				cityInfo:[],
				isArea: false,
				real_name: '',
				addres: '',
				acreage: '',
				room: '',
				
				projectIndex: 0,
				projectList: [],
				addressList: [
					{
						
					}
				],
				change: false,
				apply_sum: 0,
				h5Data:{},
				
				isIdeal: true,
				wantTo: ['写字楼','厂房','商铺','公寓'],
				wantToIndex: 0
			};
		},
		onLoad: function (options) {
			let self = this;
			self.recommendedBy(app.globalData.spid ? app.globalData.spid : self.$Cache.get("spread"));
			uni.getSystemInfo({
				success: (res) => {
					if (res.platform.toLowerCase() == 'ios' && this.getSystem(res.system)) {
						self.appleShow = true
					}
				}
			});
		},
		mounted: function() {
			this.getLogoImage();
			this.getIndexData();
		},
		computed: {
			isSend() {
				if (this.invitationCode.length == 0) {
					this.isVerify = false;
					return false;
				} else {
					return true;
				}
			},
			addressText(){
				return this.cityInfo.map(v=>v.label).join('/');
			}
		},
		methods: {
			setValue: function(event) {
				let that = this;
			},
			inputConfirm: function(event) {
				let that = this;
				that.ids = event.id;
			},
			addApply: function() {
				this.change = true;
			},
			
			closeChange: function(msg) {
				this.change = msg;
			},
			
			saveApply: function(opt) {
				let that = this,
					data = {},
					name = opt.name;
				
				if (!name) {
					return that.$util.Tips({
						title: '请输入项目名称'
					});
				}
				applySaveApi(opt).then(res => {
					console.log('>>>>>>>>>>>>>>>>>',res)
					that.change = false;
					that.projectList = res.data;
					that.$util.Tips({
						title: '创建成功',
						icon: 'success'
					})
				}).catch(msg => {
					console.log('>>>>',msg)
					that.change = false;
					that.$util.Tips({
						title: '创建失败',
						icon: 'none'
					})
				});
			},
			
			add(e){
				let that = this;
				let data = {
					id:that.addressList.length,
					name:'自定义区域'
				}
				that.addressList.splice((Number(e)+1),0,data);
			},
			del(e){
				let that = this;
				that.addressList.splice(e,1);
			},
			changeRegion(){
				this.display = true;
			},
			OnChangeAddress(address){
				this.latitude = ''
				this.longitude = ''
				this.isStreet = 0
				this.cityInfo = address;
				console.log('地址>>>>',this.cityInfo)
			},
			changeClose: function() {
				this.display = false;
			},
			
			bindPickerChange: function(e) {
				console.log('picker发送选择改变，携带值为', e.detail.value)
				this.role = e.detail.value;
				switch(e.detail.value){
					case 0:
						this.isIdeal = true;
						this.isArea = false;
						this.isHouseType = false;
						break;
					case 1:
						this.isArea = true;
						this.isHouseType = false;
						this.isIdeal = false;
						break;
					case 2:
						this.isArea = false;
						this.isHouseType = true;
						this.isIdeal = false;
						break;
					case 3:
						this.isHouseType = false;
						this.isIdeal = false;
						this.isArea = false;
						break;
				}
			},
			houseTypeChange: function(e) {
				console.log('picker发送选择改变，携带值为', e.detail.value)
				this.houseTypeIndex = e.detail.value;
			},
			projectChange: function(e) {
				console.log('picker发送选择改变，携带值为', e.detail.value)
				this.projectIndex = e.detail.value;
			},
			wantToChange: function(e) {
				console.log('picker发送选择改变，携带值为', e.detail.value)
				this.wantToIndex = e.detail.value;
			},
			// 发送消息
			sendText() {
				if (!this.isSend || this.invitationCode === 0) {
					return this.$util.Tips({
						title: '请输入您的问题',
						icon: 'none',
						duration: 1000,
						mask: true,
					});
				}
				this.recommendedBy(this.invitationCode);
			},
			recommendedBy(e) {
				let that = this;
				console.log('>>>>>>>验证推荐人',e)
				recommendedByApi({
					spread_spid: e
				}).then(res => {
					console.log('>>>>>>>验证推荐人',res.data)
					that.recommended = res.data;
					this.isVerify = true;
				}).catch(res => {
					console.log('>>>>>>>验证推荐人',res)
				});
			},
			getIndexData() {
				let that = this;
				getIndexData().then(res => {
					console.log('>>>>>>>',res)
					that.site_name = res.data.site_name;
					that.projectList = res.data.projectList;
				});
			},
			
			phoneNumShow(phone) {
				let that = this;
				return phone.substring(0, 3) + '****' + phone.substring(7);
			},
			
			nameShow(name) {
				let that = this;
				return name.substring(0, 1) + '*' + name.substring(2);
			},
			// 登录注册切换
			formItemTab: function(e){
				this.formItem = e;
			},
			// 是否勾选协议
			ChangeIsDefault(e) {
				this.$set(this, 'protocol', !this.protocol);
			},
			// 请求logo数据
			async getLogoImage() {
				let that = this;
				getLogo(2).then(res => {
					that.logoUrl = res.data.logo_url;
				});
			},
			// IOS 版本号判断
			getSystem(system) {
				let str
				system.toLowerCase().indexOf('ios') === -1 ? str = system : str = system.split(' ')[1]
				if (str.indexOf('.'))
					return str.split('.')[0] >= 13
				return str >= 13
			},
			// 获取短信验证码
			code() {
				let that = this;
				if (!that.account) return that.$util.Tips({
					title: '请填写手机号码'
				});
				if (!that.protocol) {
					this.inAnimation = true;
					return that.$util.Tips({
						title: '请先阅读并同意协议'
					});
				}
				if (!/^1(3|4|5|7|8|9|6)\d{9}$/i.test(that.account)) return that.$util.Tips({
					title: '请输入正确的手机号码'
				});
				this.isShow = true;
			},
			// 滑动验证块成功
			onSuccess() {
				let that = this;
				getCodeApi().then(res => {
					console.log('获取验证码',res)
					that.keyCode = res.data.key;
					that.getCode();
				}).catch(res => {
					that.$util.Tips({
						title: res
					});
				});
				this.isShow = false; // 通过验证后
			},
			// 发送验证码
			async getCode() {
				let that = this;
				if (!that.account) return that.$util.Tips({
					title: '请填写手机号码'
				});
				if (!/^1(3|4|5|7|8|9|6)\d{9}$/i.test(that.account)) return that.$util.Tips({
					title: '请输入正确的手机号码'
				});
				if (that.formItem == 2) that.type = "register";
				console.log('>>>>>>>',that.keyCode)
				await registerVerify({
					phone: that.account,
					type: that.type,
					key: that.keyCode,
					code: that.codeVal
				}).then(res => {
					console.log('获取验证码',res)
					that.$util.Tips({
						title: '发送成功'
					});
					that.sendCode();
				}).catch(res => {
					console.log('获取验证码失败',res)
					that.$util.Tips({
						title: res
					});
				});
			},
			// 用户点击遮罩层，应该关闭模态框
			onClose() {
			    this.isShow = false;
			},
			// 账号登录
			async submit() {
				let that = this;
				if (!that.protocol) {
					this.inAnimation = true
					return that.$util.Tips({
						title: '请先阅读并同意协议'
					});
				}
				if (!that.account) return that.$util.Tips({
					title: '请填写账号'
				});
				if (!/^[\w\d]{5,16}$/i.test(that.account)) return that.$util.Tips({
					title: '请输入正确的账号'
				});
				if (!that.password) return that.$util.Tips({
					title: '请填写密码'
				});
				if (this.keyLock) {
					this.keyLock = !this.keyLock
				} else {
					return that.$util.Tips({
						title: '请勿重复点击'
					});
				}
				
				loginH5({
					account: that.account,
					password: that.password,
					spread: that.$Cache.get("spread")
				}).then(({ data }) => {
					console.log('登录成功')
					that.$store.commit("LOGIN", {
						'token': data.token,
						'time': data.expires_time - this.$Cache.time()
					});
					let backUrl = that.$Cache.get(BACK_URL) || "/pages/index/index";
					that.$Cache.clear(BACK_URL);
					getUserInfo().then(res => {
						this.keyLock = true
						that.$store.commit("SETUID", res.data.uid);
						that.$store.commit("UPDATE_USERINFO", res.data);
						if (backUrl.indexOf('/pages/users/login/index') !== -1) {
							backUrl = '/pages/index/index';
						}
						if(backUrl == "/pages/index/index"){
							uni.switchTab({
								url: backUrl
							})
						} else {
							uni.reLaunch({
								url: backUrl
							});
						}
					}).catch(error => {
						console.log('获取用户信息失败',error)
						this.keyLock = true
					})
				}).catch(e => {
					console.log('>>>',e)
					this.keyLock = true
					that.$util.Tips({
						title: e
					});
				});
			},
			// 快速登录
			async loginMobile() {
				let that = this;
				if (!that.protocol) {
					this.inAnimation = true
					return that.$util.Tips({
						title: '请先阅读并同意协议'
					});
				}
				if (!that.account) return that.$util.Tips({
					title: '请填写手机号码'
				});
				if (!/^1(3|4|5|7|8|9|6)\d{9}$/i.test(that.account)) return that.$util.Tips({
					title: '请输入正确的手机号码'
				});
				if (!that.captcha) return that.$util.Tips({
					title: '请填写验证码'
				});
				if (!/^[\w\d]+$/i.test(that.captcha)) return that.$util.Tips({
					title: '请输入正确的验证码'
				});

				if (that.appLoginStatus) {
					that.wxLoginApi()
				} else if (that.appleLoginStatus) {
					that.appleLoginApi()
				} else {
					if (this.keyLock) {
						this.keyLock = !this.keyLock
					} else {
						return that.$util.Tips({
							title: '请勿重复点击'
						});
					}
					console.log('邀请码',that.spread?that.spread:that.$Cache.get("spread"))
					loginMobile({
						phone: that.account,
						captcha: that.captcha,
						spread: that.spread ? that.spread : that.$Cache.get("spread")
					}).then(res => {
						console.log('手机登录',res)
						let data = res.data;
						that.$store.commit("LOGIN", {
							'token': data.token,
							'time': data.expires_time - this.$Cache.time()
						});
						let backUrl = that.$Cache.get(BACK_URL) || "/pages/index/index";
						that.$Cache.clear(BACK_URL);
						getUserInfo().then(res => {
							console.log('手机登录>>>>>>>',backUrl)
							console.log('手机登录>>>>>>><<<<<<',res)
							this.keyLock = true
							that.$store.commit("SETUID", res.data.uid);
							that.$store.commit("UPDATE_USERINFO", res.data);
							if (backUrl.indexOf('/pages/users/login/index') !== -1) {
								backUrl = '/pages/index/index';
							}
							if(backUrl == "/pages/index/index" && backUrl == "/pages/user/index"){
								uni.switchTab({
									url: backUrl
								})
							} else {
								uni.reLaunch({
									url: backUrl
								});
							}
						})
					}).catch(res => {
						console.log('手机登录失败',res)
						this.keyLock = true
						that.$util.Tips({
							title: res
						});
					});
				}

			},
			// 注册
			async register() {
				let that = this,
					value = {},
					regionArray = that.cityInfo;
				
				if (!that.real_name) return that.$util.Tips({
					title: '请填写联系人'
				});
				if(regionArray.length == 0) return that.$util.Tips({
					title: '请选择城市'
				});
				if (!that.addres) return that.$util.Tips({
					title: '请输入详情地址'
				});
				if (!that.account) return that.$util.Tips({
					title: '请填写手机号码'
				});
				if (!/^1(3|4|5|7|8|9|6)\d{9}$/i.test(that.account)) return that.$util.Tips({
					title: '请输入正确的手机号码'
				});
				if (!that.password) return that.$util.Tips({
					title: '请填写密码'
				});
				if (/^([0-9]|[a-z]|[A-Z]){0,6}$/i.test(that.password)) return that.$util.Tips({
					title: '您输入的密码过于简单'
				});
				if (!that.captcha) return that.$util.Tips({
					title: '请填写验证码'
				});
				if (!/^[\w\d]+$/i.test(that.captcha)) return that.$util.Tips({
					title: '请输入正确的验证码'
				});
				if (!that.invitationCode) return that.$util.Tips({
					title: '请输入邀请码'
				});
				if (!that.isVerify) return that.$util.Tips({
					title: '邀请码未通过验证'
				});
				
				value.city = {
					province: regionArray[0].label,
					city: regionArray[1].label,
					district: regionArray[2].label,
					street: regionArray[3]?regionArray[3].label:''
				};
				
				value.real_name = that.real_name;
				value.role = that.role;
				value.addres = that.addres;
				value.acreage = that.acreage;
				value.room = that.room;
				
				
				value.account = that.account;
				value.captcha = that.captcha;
				value.password = that.password;
				value.spread = that.invitationCode;
				
				value.project = that.projectList[that.projectIndex];
				value.house_type = that.houseType[that.houseTypeIndex];
				value.want_to = that.wantTo[that.wantToIndex];
				
				let address_arr = [];
				for (var i = 0; i < that.addressList.length; i++) {
					let item = that.addressList[i];
					address_arr[i] = item.name;
				}
				value.address_arr = address_arr;
				console.log(JSON.stringify(address_arr))
				console.log('>>>>>>>>>',address_arr)
				console.log('>>>>>>>>>>提交注册',value)
				//return
				register(value).then(res => {
					console.log('>>>>>>>>>>提交注册',res)
					that.$util.Tips({
						title: res
					});
					that.formItem = 1;
				}).catch(res => {
					console.log('>>>>>>>>>>提交注册',res)
					that.$util.Tips({
						title: res
					});
				});
			},
			
			// 苹果登录
			appleLogin() {
				let self = this
				this.account = ''
				this.captcha = ''
				if (!self.protocol) {
					this.inAnimation = true
					return self.$util.Tips({
						title: '请先阅读并同意协议'
					});
				}
				uni.showLoading({
					title: '登录中'
				})
				uni.login({
					provider: 'apple',
					timeout: 10000,
					success(loginRes) {
						uni.getUserInfo({
							provider: 'apple',
							success: function(infoRes) {
								self.appleUserInfo = infoRes.userInfo
								self.appleLoginApi()
							},
							fail() {
								uni.showToast({
									title: '获取用户信息失败',
									icon: 'none',
									duration: 2000
								})
							},
							complete() {
								uni.hideLoading()
							}
						});
					},
					fail(error) {
						console.log(error)
					}
				})
			},
			// 苹果登录Api
			appleLoginApi() {
				let self = this
				appleLogin({
					openId: self.appleUserInfo.openId,
					email: self.appleUserInfo.email || '',
					phone: this.account,
					captcha: this.captcha
				}).then(({
					data
				}) => {
					if (data.isbind) {
						uni.showModal({
							title: '提示',
							content: '请绑定手机号后，继续操作',
							showCancel: false,
							success: function(res) {
								if (res.confirm) {
									self.current = 1
									self.appleLoginStatus = true
								}
							}
						});
					} else {
						self.$store.commit("LOGIN", {
							'token': data.token,
							'time': data.expires_time - self.$Cache.time()
						});
						let backUrl = self.$Cache.get(BACK_URL) || "/pages/index/index";
						self.$Cache.clear(BACK_URL);
						self.$store.commit("SETUID", data.userInfo.uid);
						self.$store.commit("UPDATE_USERINFO", data.userInfo);
						uni.reLaunch({
							url: backUrl
						});
					}
				}).catch(error => {
					uni.showModal({
						title: '提示',
						content: `错误信息${error}`,
						success: function(res) {
							if (res.confirm) {
								console.log('用户点击确定');
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					});
				})
			},
			// App微信登录
			wxLogin() {
				if (!this.protocol) {
					this.inAnimation = true
					return this.$util.Tips({
						title: '请先阅读并同意协议'
					});
				}
				let self = this
				this.account = ''
				this.captcha = ''
				uni.showLoading({
					title: '登录中'
				})
				uni.login({
					provider: 'weixin',
					success: function(loginRes) {
						// 获取用户信息
						uni.getUserInfo({
							provider: 'weixin',
							success: function(infoRes) {
								self.appUserInfo = infoRes.userInfo
								self.wxLoginApi()
							},
							fail() {
								uni.showToast({
									title: '获取用户信息失败',
									icon: 'none',
									duration: 2000
								})
							},
							complete() {
								uni.hideLoading()
							}
						});
					},
					fail() {
						uni.showToast({
							title: '登录失败',
							icon: 'none',
							duration: 2000
						})
					}
				});
			},
			
			wxLoginApi() {
				let self = this
				wechatAppAuth({
					userInfo: self.appUserInfo,
					phone: this.account,
					code: this.captcha
				}).then(({
					data
				}) => {
					if (data.isbind) {
						uni.showModal({
							title: '提示',
							content: '请绑定手机号后，继续操作',
							showCancel: false,
							success: function(res) {
								if (res.confirm) {
									self.current = 1
									self.appLoginStatus = true
								}
							}
						});
					} else {
						self.$store.commit("LOGIN", {
							'token': data.token,
							'time': data.expires_time - self.$Cache.time()
						});
						let backUrl = self.$Cache.get(BACK_URL) || "/pages/index/index";
						self.$Cache.clear(BACK_URL);
						self.$store.commit("SETUID", data.userInfo.uid);
						self.$store.commit("UPDATE_USERINFO", data.userInfo);
						uni.reLaunch({
							url: backUrl
						});
					}
				}).catch(error => {
					uni.showModal({
						title: '提示',
						content: `错误信息${error}`,
						success: function(res) {
							if (res.confirm) {
								console.log('用户点击确定');
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					});
				})
			},
			again() {
				this.codeUrl =
					VUE_APP_API_URL +
					"/sms_captcha?" +
					"key=" +
					this.keyCode +
					Date.parse(new Date());
			},
			privacy(type) {
				uni.navigateTo({
					url: "/pages/users/privacy/index?type=" + type
				})
			}
		}
	};
</script>

<style lang="scss">
	/deep/uni-checkbox .uni-checkbox-input {
		margin-top: -6rpx;
	}

	.appLogin {
		margin-top: 60rpx;

		.hds {
			display: flex;
			justify-content: center;
			align-items: center;
			font-size: 24rpx;
			color: #B4B4B4;

			.line {
				width: 68rpx;
				height: 1rpx;
				background: #CCCCCC;
			}

			p {
				margin: 0 20rpx;
			}
		}

		.btn-wrapper {
			display: flex;
			align-items: center;
			justify-content: center;
			margin-top: 30rpx;

			.btn {
				display: flex;
				align-items: center;
				justify-content: center;
				width: 68rpx;
				height: 68rpx;
				border-radius: 50%;
			}

			.apple-btn {
				display: flex;
				align-items: center;
				justify-content: center;
				width: 246rpx;
				height: 66rpx;
				margin-left: 30rpx;
				background: #EAEAEA;
				border-radius: 34rpx;
				font-size: 24rpx;

				.icon-s-pingguo {
					color: #333;
					margin-right: 10rpx;
					font-size: 34rpx;
				}
			}

			.iconfont {
				font-size: 40rpx;
				color: #fff;
			}

			.wx {
				background-color: #61C64F;
			}

			.mima {
				background-color: #28B3E9;
			}

			.yanzheng {
				background-color: #F89C23;
			}

			.pingguo {
				margin-left: 60rpx;
				background-color: #000;
			}

		}
	}

	.main-color {
		color: var(--view-theme);
	}

	.code img {
		width: 100%;
		height: 100%;
	}

	.acea-row.row-middle {
		input {
			margin-left: 20rpx;
			display: block;
		}
	}

	.login-wrapper {
		padding-bottom: 80rpx;
		.login-top {
			height: 358rpx;
			background-color: var(--view-minorColor);
			background-image: url('../static/login.png');
			background-size: cover;
			background-repeat: no-repeat;

			image {
				width: 101%;
				height: 100%;
			}
		}

		.shading {
			display: flex;
			align-items: center;
			justify-content: center;
			width: 100%;
			margin-top: -300rpx;
			position: relative;

			image {
				width: 180rpx;
				height: 180rpx;
				top: 0rpx;
			}
		}

		.whiteBg {
			background-color: #fff;
			margin: -30rpx 56rpx 0rpx 56rpx;
			box-shadow: 0px 2px 14px 0px rgba(0, 0, 0, 0.08);
			border-radius: 8px;
			padding: 30rpx;

			.tips {
				display: flex;
				align-items: center;
				justify-content: center;
				height: 50rpx;
				margin: 40rpx;
				color: #999;

				.tips-btn {
					margin: 0 31rpx 0 48rpx;
					color: #999999;
					font-weight: bold;
					font-size: 32rpx;


					/* Safari 与 Chrome */
					.line {
						width: 80rpx;
						height: 6rpx;
						background: linear-gradient(135deg, var(--view-minorColor) 0%, var(--view-theme) 100%);
						border-radius: 2px;
						margin: 10rpx auto 0 auto;
						animation: myfirst .3s;
						-webkit-animation: myfirst .3s;
					}

					.none {
						width: 80rpx;
						background: #fff;
						height: 6rpx;
					}
				}

				@keyframes myfirst {
					0% {
						width: 0rpx;
					}

					100% {
						width: 80rpx;
					}
				}

				@-webkit-keyframes myfirst

				/* Safari 与 Chrome */
					{
					0% {
						width: 0rpx;
					}

					100% {
						width: 80rpx;
					}
				}

				.tips-btn.on {
					font-size: 36rpx;
					color: var(--view-theme);
				}
			}

			.list {
				border-radius: 16rpx;
				overflow: hidden;

				.forgetPwd {
					text-align: right;
					margin-top: 10rpx;
					color: #666666;
					font-size: 24rpx;
				}

				.item {
					background: #fff;
					border-bottom: 1px solid #F0F0F0;
					.itemImg-add {
					  width: 24rpx;
					   height: 34rpx;
					}
					.item-img {
					  width: 28rpx; 
					  height: 32rpx;
					}
					.InvitationCode{
					  width: 28rpx; 
					  height: 28rpx;
					  &.address{
						  margin-right: 20rpx;
					  }
					}
					.acea-row{
						position: relative;
						padding: 10rpx 20rpx;
						
						input {
							flex: 1;
							font-size: 28rpx;
							height: 80rpx;
						}
						
						.code {
							position: absolute;
							right: 30rpx;
							top: 50%;
							color: var(--view-theme);
							font-size: 26rpx;
							transform: translateY(-50%);
						}
						.uni-list-cell-left{
							color: #999;
							text{
								font-size: 26rpx;
							}
							&.on{
								text{
									font-size: 32rpx;
								}
							}
						}
						.uni-list-cell-db{
							margin-left: 30rpx;
						}
					}
					.input-box {
						display: flex;
						align-items: center;
						flex: 1;
						.icon-yanzhengma {
							font-size: 28rpx;
							color: #ddf8e4;
							font-weight: normal;
							margin-left: 30rpx;
							margin-bottom: 0rpx;
							display: none;
						}
						.isSend {
							color: $kf-theme;
							color: var(--view-theme);
							display: block;
						}
					}
					.addressCon{
						padding: 20rpx;
					}
					&.on{
						padding: 20rpx 0rpx;
					}
				}
				.user-info{
					padding: 30rpx 0;
					text-align: center;
					.user-info-top{
						padding: 30rpx 0;
						.top-image{
							image{
								width: 80rpx;
								height: 80rpx;
								border-radius: 50%;
							}
						}
						.top-nickname{
							margin-left: 20rpx;
							text{
								margin-left: 30rpx;
							}
						}
					}
					.user-info-down{
						text-align: center;
					}
				}
			}

			.logon {
				display: flex;
				align-items: center;
				justify-content: center;
				width: 100%;
				height: 86rpx;
				margin-top: 48rpx;
				background: linear-gradient(135deg, var(--view-minorColor) 0%, var(--view-theme) 100%);
				border-radius: 120rpx;
				color: #FFFFFF;
				font-size: 30rpx;
			}
			
			.register {
				display: flex;
				align-items: center;
				justify-content: center;
				width: 100%;
				height: 86rpx;
				margin-top: 20rpx;
				border: solid 1rpx var(--view-theme);
				border-radius: 120rpx;
				color: var(--view-minorColor);
				font-size: 30rpx;
			}
		}

		.protocol {
			margin-top: 40rpx;
			color: #999999;
			font-size: 24rpx;
		}

		.trembling {
			animation: shake 0.6s;
		}

		@keyframes shake {

			0%,
			100% {
				-webkit-transform: translateX(0);
			}

			10%,
			30%,
			50%,
			70%,
			90% {
				-webkit-transform: translateX(-5rpx);
			}

			20%,
			40%,
			60%,
			80% {
				-webkit-transform: translateX(5rpx);
			}
		}

		@-o-keyframes shake {

			/* Opera */
			0%,
			100% {
				-webkit-transform: translateX(0);
			}

			10%,
			30%,
			50%,
			70%,
			90% {
				-webkit-transform: translateX(-5rpx);
			}

			20%,
			40%,
			60%,
			80% {
				-webkit-transform: translateX(5rpx);
			}
		}

		@-webkit-keyframes shake {

			/* Safari 和 Chrome */
			0%,
			100% {
				-webkit-transform: translateX(0);
			}

			10%,
			30%,
			50%,
			70%,
			90% {
				-webkit-transform: translateX(-5rpx);
			}

			20%,
			40%,
			60%,
			80% {
				-webkit-transform: translateX(5rpx);
			}
		}

		@-moz-keyframes shake {

			/* Firefox */
			0%,
			100% {
				-moz-transform: translateX(0);
			}

			10%,
			30%,
			50%,
			70%,
			90% {
				-moz-transform: translateX(-5rpx);
			}

			20%,
			40%,
			60%,
			80% {
				-moz-transform: translateX(5rpx);
			}
		}
	}
</style>